<?php
/*
Template Name: Askadoc
*/
/* 
Author: Bipul Luitel
Template for Ask A Doctor feature of Okhati
*/
?>
<?php 
get_header();
?>
	<div id="Ocontent">
		<div id="Opopup">	
		</div>
		<div id="Omainbox">
          <div class="apage">
            <h1 class="titlehead"><a href="ask-a-doctor">Ask A Doctor</a></h1>
			<h3 class="intext">Your questions answered by healthcare professionals</h3>
			
			<?php 
			// Question Form 
			?>
			<div id="qform">
				<form action="#" method="post" id="questionform" name="questionform">
					<input type="text" name="qtitle" id="qtitle" />
					<input type="submit" value="Search" name="qsearch" id="qsearch" />
				</form>
			</div>
			<?php 
			// Questions/Answer List
			// Set parameters for new pods
			$params = array(
					'orderby' => 't.modified DESC',
					'limit' => 20,
					);
			$myq = pods('questions',$params);
			//Log in status
			if(is_user_logged_in())
			$logged = 1;
			else
			$logged = 0;
			
			?>
			<div id="qanda">
				<div id="qbox">
					<span>Question</span>
					<input type="text" id="quest" />
					<span>Brief Description</span>
					<textarea id="quesd">
					<?php echo ($logged==1)?'':'Please log in to ask questions!';?></textarea>
					<span>Stay Anonymous </span>
					<input type="checkbox" id="anon" />
					<input type="submit" id="qsubmit" value="Ask" <?php echo ($logged==1)?'':'disabled = "disabled"';?> onclick="postQuestion()" />
				</div>
					
			<?php 	
				$a = 1;
				while($myq->fetch()): 
				$anon = ($myq->display('anonymous') == "Yes")?"Anonymous":$myq->display('author');
				$qid = $myq->display('id');
				$subdate = strtotime($myq->display('created'));
				$subdateE1 = substr($subdate, 0, 4);
				$subdateE2 = strrev(substr($subdate, 4));
				
				
				
				// Answers to questions
				$params1 = array(
						'orderby' => 't.modified DESC',
						'where' => 't.qid = '.$qid
						);
				$myans = pods('answers',$params1);
				$totalans = $myans->total_found();
					

				?>
				<div class="qquest" id="addform-<?php echo $qid; ?>">
					<?php if (current_user_can('administrator')): ?>
					<a class="absrightdel" href="javascript:doqdel(<?php echo $qid.$subdateE1.','.$subdateE2.','.$qid;?>)">x</a>
					<?php endif; ?>
					<?php 
					echo '<span class="qtitle">'.$a.'. <a href="javascript:void(0)" onClick="toggleIt(\'qquest-'.$qid.'\')">'.$myq->display('title').'</a></span>';
					echo '<span class="qdesc">'.$myq->display('description').'</span>';
					?>
					<div class="qquestmeta">
					<?php
					echo '<span class="qauth"> - '.$anon.' On '.$myq->display('created').'</span>';
					if($totalans > 0){
					echo '<span class="qauthans"><a href="javascript:void(0)" onclick="toggleIt(\'qquest-'.$qid.'\');">View Answers ('.$totalans.')</a></span>';
					}
					if (current_user_can('administrator')): ?>
						<span class="qauthans" ><a href="javascript:void(0)" onClick="insertForm('addform-<?php echo $qid; ?>')">Answer it</a></span>
					<?php endif; ?>
					</div>
				</div>
				<div class="ansgrup" id="qquest-<?php echo $qid; ?>" style="display:none">
					<?php

					//Search for all the answers to that question
					$a = $a + 1;
					while($myans->fetch()):
					$authname = (strtoupper($myans->display('anonymous')) == 'NO')?$myans->display('author'):'Anonymous';
					?>
					<div class="qans">
						<?php 
						echo '<span class="ansauth">'.$authname." On ".$myans->display('modified')."</span>";
						echo '<span class="ansdesc">'.$myans->display('answer')."</span>";
						?>
					</div>
					<?php
					endwhile;
					?>
				</div>
				<?php
				endwhile;
				?>
			</div>
            <div class="clear"> </div>
          </div><!-- post_class() -->
			<div class="clear"> </div>
		</div>
	</div>
	<?php get_sidebar(); ?>
	<?php wp_footer(); ?>